package com.atguigu.gmall.controller;

import com.atguigu.gmall.entity.PlatformPropertyKey;
import com.atguigu.gmall.entity.PlatformPropertyValue;
import com.atguigu.gmall.entity.SkuPlatformPropertyValue;
import com.atguigu.gmall.result.RetVal;
import com.atguigu.gmall.service.PlatformPropertyKeyService;
import com.atguigu.gmall.service.PlatformPropertyValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.event.ItemEvent;
import java.util.List;

@RestController
@RequestMapping("/product")
public class PlatformPropertyController {
    @Autowired
    private PlatformPropertyKeyService propertyKeyService;
    @Autowired
    private PlatformPropertyValueService propertyValueService;

    //1.根据分类Id获取平台属性key和value集合
    @GetMapping("getPlatformPropertyByCategoryId/{category1Id}/{category2Id}/{category3Id}")
    public RetVal getPlatformPropertyByCategoryId(
            @PathVariable Long category1Id,
            @PathVariable Long category2Id,
            @PathVariable Long category3Id){
        List<PlatformPropertyKey> platformPropertyList=propertyKeyService.getPlatformPropertyByCategoryId(category1Id,category2Id,category3Id);
        return RetVal.ok(platformPropertyList);
    }

    //2.根据平台属性key获取平台属性值集合
    @GetMapping("getPropertyValueByPropertyKeyId/{propertyKeyId}")
    public RetVal getPropertyValueByPropertyKeyId(@PathVariable Long propertyKeyId){
        List<PlatformPropertyValue> propertyValueList=propertyValueService.getPropertyValueByPropertyKeyId(propertyKeyId);
        return RetVal.ok(propertyValueList);
    }

    //3.保存属性
    @PostMapping("savePlatformProperty")
    public RetVal savePlatformProperty(@RequestBody PlatformPropertyKey platformPropertyKey){
        propertyKeyService.savePlatformProperty(platformPropertyKey);
        return RetVal.ok();
    }

    @PostMapping("getPlatformProperty")
    public List<PlatformPropertyKey> getPlatformProperty( @RequestBody List<SkuPlatformPropertyValue> values){
        return propertyKeyService.getPlatformProperty(values);
    }

}
